<template>
	<view class="mian">
		<view class="wrap">
			<view class="u-tabs-box">
				<u-tabs-swiper 
					activeColor="#f29100" 
					ref="tabs" 
					:list="list" 
					:current="current" 
					@change="change" 
					:is-scroll="false" 
					swiperWidth="750">
				</u-tabs-swiper>
			</view>
			<view class="data-box">
				<view v-show="!startDate">全部</view>
				<view v-show="startDate">{{startDate}}--{{endDate}}</view>
				<view @click="calendarVisible=true">选择时间</view>
			</view>
			<swiper 
				class="swiper-box" 
				:current="swiperCurrent" 
				@transition="transition" 
				@animationfinish="animationfinish">
				<swiper-item class="swiper-item">
					<scroll-view scroll-y style="height: 100%;width: 100%;" @scrolltolower="reachBottom">
						<view class="page-box">
							<view v-if="orderList[0].length > 0">
								<view class="order" v-for="(res, index) in orderList[0]" :key="res.FBillNo">
									<view class="top">
										<view class="left">
											<u-icon name="home" :size="30" color="rgb(94,94,94)"></u-icon>
											<view class="store">{{ res.StockName }}</view>
											<u-icon name="arrow-right" color="rgb(203,203,203)" :size="26"></u-icon>
										</view>
									</view>
									<view class="item">
										<view class="content">
											<view class="title u-line-2">{{ res.FRemark }}</view>
											<view class="delivery-time"> {{ res.FDate }}</view>
										</view>
										<view class="right">
											<view class="price">
												￥{{ res.mFAmount}}
											</view>
										</view>
									</view>
								</view>
							</view>
							<view class="centre" v-else>
								<image :src="require('@/static/taobao-order.png')" mode=""></image>
								<view class="explain">
									您还没有相关的数据
									<view class="tips">You have no relevant data</view>
								</view>
							</view>
						</view>
					</scroll-view>
				</swiper-item>
				<swiper-item class="swiper-item">
					<scroll-view scroll-y style="height: 100%;width: 100%;" @scrolltolower="reachBottom">
						<view class="page-box">
							<view v-if="orderList[1].length > 0">
								<view class="order" v-for="(res, index) in orderList[1]" :key="res.FBillNo">
									<view class="top">
										<view class="left">
											<u-icon name="home" :size="30" color="rgb(94,94,94)"></u-icon>
											<view class="store">{{ res.StockName }}</view>
											<u-icon name="arrow-right" color="rgb(203,203,203)" :size="26"></u-icon>
										</view>
									</view>
									<view class="item">
										<view class="content">
											<view class="title u-line-2">{{ res.FRemark }}</view>
											<view class="delivery-time"> {{ res.FDate }}</view>
										</view>
										<view class="right">
											<view class="price">
												￥{{ res.mFAmount}}
											</view>
										</view>
									</view>
								</view>
							</view>
							<view class="centre" v-else>
								<image :src="require('@/static/taobao-order.png')" mode=""></image>
								<view class="explain">
									您还没有相关的数据
									<view class="tips">You have no relevant data</view>
								</view>
							</view>
						</view>
					</scroll-view>
				</swiper-item>
				<swiper-item class="swiper-item">
					<scroll-view scroll-y style="height: 100%;width: 100%;">
						<view class="page-box">
							<view v-if="orderList[2].length > 0">
								<view class="order" v-for="(res, index) in orderList[2]" :key="res.FBillNo">
									<view class="top">
										<view class="left">
											<u-icon name="home" :size="30" color="rgb(94,94,94)"></u-icon>
											<view class="store">{{ res.StockName }}</view>
											<u-icon name="arrow-right" color="rgb(203,203,203)" :size="26"></u-icon>
										</view>
									</view>
									<view class="item">
										<view class="content">
											<view class="title u-line-2">{{res.MemberTimeName}}/{{ res.FRemark }}</view>
											<view class="delivery-time"> {{ res.FDate }}</view>
										</view>
										<view class="right">
											<view class="price">
												￥{{ res.mFAmount}}/{{res.FQty}}次
											</view>
										</view>
									</view>
								</view>
							</view>
							<view class="centre" v-else>
								<image :src="require('@/static/taobao-order.png')" mode=""></image>
								<view class="explain">
									您还没有相关的数据
									<view class="tips">You have no relevant data</view>
								</view>
							</view>
							
						</view>
					</scroll-view>
				</swiper-item>
			</swiper>
		</view>
		<view class="bottom-bar">
			<view class="left">
				<text class="base-title">当前余额:</text>
				<text class="price">
					<text class="synbol">￥</text>
					{{money}}
				</text>
			</view>
			<text 
				class="topUp" 
				@click="navTo('/pages/MemberTopUp/MemberTopUp')">
				去充值
			</text>
		</view>
		<u-calendar v-model="calendarVisible" mode="range" @change="onDateChange"></u-calendar>
	</view>
</template>

<script>
export default {
	data() {
		return {
			calendarVisible:false,
			startDate:'',
			endDate:'',
			orderList: [[], [], []],
			list: [ 
				{ name: '充值' },
				{ name: '消费' },
				{ name: '次卡' }
			],
			money: 0 ,
			current: 0,
			swiperCurrent: 0,
			tabsHeight: 0,
			dx: 0,
			dty: 1,
			loadStatus: ['nomore','loadmore','loadmore'],
		};
	},
	onShow(){
		this.money = uni.getStorageSync('Members')[0].Amount;
	},
	onLoad() {
		this.getOrderList(this.current);
	},
	computed: {
	},
	methods: {
		navTo(url) {
			uni.navigateTo({
				url: url,
			})
		},
		onDateChange(e) {
			this.startDate = e.startDate
			this.endDate = e.endDate
			this.getOrderList(this.current)
		},
		reachBottom() {
			// 此tab为空数据
			this.getOrderList(this.current)
			// if(this.current != 2) {
			// 	this.loadStatus.splice(this.current,1,"loading")
			// 	setTimeout(() => {
			// 		this.getOrderList(this.current);
			// 	}, 1200);
			// }
		},
		// 页面数据
		async getOrderList(idx) {
			if(idx === 0){
				this.dty = 1
			}else if(idx === 1){
				this.dty = -1
			}else if(idx === 2){
				this.dty = 3
			}
			let list = await this.$util.util('MemberShop/GetMemberDeposit', {
				DataType: this.dty,
				DateStar: this.startDate || '',
				DateEnd:this.endDate || '',
				PageIndex: 1,
				PageSize: 999,
			}, 'GET');
			let newArr = list.filter(item=>!this.orderList[idx].some(ele=>ele.FCorpID===item.FCorpID)) 
			this.orderList[idx].push(...newArr)
			// console.log('sdas', this.orderList[idx])
			// this.loadStatus.splice(this.current,1,"loadmore")
		},
		// 总价
		totalPrice(item) {
			let price = 0;
			item.map(val => {
				price += parseFloat(val.price);
			});
			return price.toFixed(2);
		},
		// tab栏切换
		change(index) {
			this.swiperCurrent = index;
			this.getOrderList(index);
			switch(index){
				case 0:
				uni.setNavigationBarTitle({ 
					title:'余额明细'
				})
				console.log(this.current)
				break;
				case 1:
				uni.setNavigationBarTitle({
			　　title:'消费明细'
				})
				break;
				case 2:
				uni.setNavigationBarTitle({
					title:'次卡明细'
				})
				break;
			}
		},
		transition({ detail: { dx } }) {
			this.$refs.tabs.setDx(dx);
		},
		animationfinish({ detail: { current } }) {
			this.$refs.tabs.setFinishCurrent(current);
			this.swiperCurrent = current;
			this.current = current;
		}
	}
};
</script>

<style lang="scss" scoped>
.mian {
	height: 100%;
	background-color: #f2f2f2;
}
.order {
	width: 710rpx;
	background-color: #ffffff;
	margin: 10rpx auto;
	border-radius: 20rpx;
	box-sizing: border-box;
	padding: 10rpx;
	font-size: 28rpx;
	.top {
		display: flex;
		justify-content: space-between;
		.left {
			display: flex;
			align-items: center;
			.store {
				margin: 0 10rpx;
				font-size: 26rpx;
				font-weight: 400;
			}
		}
		.right {
			color: $u-type-warning-dark;
		}
	}
	.item {
		display: flex;
		// margin: 20rpx 0 0;
		.left {
			margin-right: 20rpx;
			image {
				width: 200rpx;
				height: 200rpx;
				border-radius: 10rpx;
			}
		}
		.content {
			width:100%;
			.title {
				font-size: 28rpx;
				line-height: 50rpx;
				color:#707070;
			}
			.type {
				margin: 10rpx 0;
				font-size: 24rpx;
				color: $u-tips-color;
			}
			.delivery-time {
				color: #A7A7A7;
				font-size: 24rpx;
			}
		}
		.right {
			flex-shrink: 0;
			margin-left: 10rpx;
			padding-top: 20rpx;
			text-align: right;
			.decimal {
				font-size: 24rpx;
				margin-top: 4rpx;
			}
			.number {
				color: $u-tips-color;
				font-size: 24rpx;
			}
		}
	}
	.total {
		margin-top: 20rpx;
		text-align: right;
		font-size: 24rpx;
		.total-price {
			font-size: 32rpx;
		}
	}
	.bottom {
		display: flex;
		margin-top: 40rpx;
		padding: 0 10rpx;
		justify-content: space-between;
		align-items: center;
		.btn {
			line-height: 52rpx;
			width: 160rpx;
			border-radius: 26rpx;
			border: 2rpx solid $u-border-color;
			font-size: 26rpx;
			text-align: center;
			color: $u-type-info-dark;
		}
		.evaluate {
			color: $u-type-warning-dark;
			border-color: $u-type-warning-dark;
		}
	}
}
.centre {
	text-align: center;
	margin: 200rpx auto;
	font-size: 32rpx;
	image {
		width: 164rpx;
		height: 164rpx;
		border-radius: 50%;
		margin-bottom: 20rpx;
	}
	.tips {
		font-size: 24rpx;
		color: #999999;
		margin-top: 20rpx;
	}
	.btn {
		margin: 80rpx auto;
		width: 200rpx;
		border-radius: 32rpx;
		line-height: 64rpx;
		color: #ffffff;
		font-size: 26rpx;
		background: linear-gradient(270deg, rgba(249, 116, 90, 1) 0%, rgba(255, 158, 1, 1) 100%);
	}
}
.wrap {
	display: flex;
	flex-direction: column;
	height: calc(100vh - var(--window-top) - env(safe-area-inset-bottom) - 100upx);
	width: 100%;
}
.swiper-box {
	flex: 1;
}
.swiper-item {
	height: 100%;
}
.bottom-bar{
	position:fixed;
	bottom:0;
	left:0;
	width: 100%;
	padding-bottom: env(safe-area-inset-bottom);
	display:flex;
	justify-content: space-between;
	background-color:rgba(255, 255, 255, 1);
	.left {
		width: 100%;
		height: 100upx;
		padding-left: 28upx;
		color: #191919;
		display: flex;
		align-items: center;
		background:linear-gradient(120deg, #f9745a 0%, #ffdd55 100%);;
	
		.base-title {
			font-size: 28upx;
			line-height: 38upx;
			display: inline-block;
			vertical-align: top;
		}
	
		.price {
			margin-left: 10upx;
			font-size: 56upx;
			line-height: 80upx;
	
			.synbol {
				font-size: 26upx;
			}
		}
	}
	.topUp {
		height: 100upx;
		display: flex;
		align-items: center;
		padding: 0 28upx;
		color: #191919;
		line-height: 80upx;
		background: linear-gradient(270deg, #f9745a 0%, #ff9e01 100%);
		color: #fff;
		flex-shrink: 0;
	}
}
	.data-box{
		position: relative;
		width: 100%;
		display:flex;
		justify-content: space-between;
		align-items: center;
		padding:20upx 28upx;
		background-color:#fefefe;
		&::after{
			display:block;
			content: '';
			height: 1px;
			width: 710upx;
			background-color: #f9745a;
			position:absolute;
			top:0;
			left:20upx;
		}
	}
</style>
